package dao;

import common.Group;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.sql.*;
import java.util.Properties;

public class GetMembers {
    //每个群成员与群对应的关系
    public Group getMembers(Group gp) {
        Connection conn = null;
        ResultSet res = null;
        Group group = new Group();
        try {
            boolean f = false;
            Properties info=new Properties();
            info.load(new FileInputStream("src\\sql.properties"));
            String user=info.getProperty("user");
            String password=info.getProperty("password");
            String Driver=info.getProperty("Driver");
            String url=info.getProperty("url");
            //注册驱动
            Class.forName(Driver);
            //获取连接
            conn = DriverManager.getConnection(url, user, password);
            String sql = "select * from grouplist where group_id = ?";
            PreparedStatement presta = conn.prepareStatement(sql);
            presta.setString(1, gp.getGroupid());
            res = presta.executeQuery();
            if (res.next()) {
                group.setOwnerid(res.getString("member_id"));
                group.setGroupstate(res.getInt("statement"));
                System.out.println("当前群聊成员信息：" + gp);
                return group;
            }
        } catch (SQLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (ClassNotFoundException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return group;
    }
}
